<script setup>
import {getCurrentInstance, onMounted, ref, watch} from "vue";
import {create} from "axios";
import {ElMessage} from "element-plus";

const {proxy} = getCurrentInstance();
const isSuccess = ref(0); //判断是否成功删除
const visible = ref(false);
const props = defineProps({
  showDialog:Boolean,
  id:Number,
  url:String
})
const emits = defineEmits(['close'])

const closeDialog = () =>{
  emits('close', false);
}


const deletePerson = async () => {
  try {
    // 使用全局的 $axios 发起请求
    isSuccess.value = (await proxy.$axios.delete(`http://localhost:8091/TbCustomer/${props.url}/${props.id}`)).data;
    if (isSuccess.value > 0) {
      ElMessage.success("操作成功");
    } else {
      ElMessage.error("操作失败");
    }
  } catch (error) {
    console.error(error);
  }
}

watch(() => props.showDialog, (val) => {
  visible.value = val
}, {immediate:true})
</script>

<template>
  <el-dialog v-model = "visible" @close = "closeDialog" width="10%">
    <div class = "module">
      <span>是否删除此用户？</span>
    </div>
    <div class = "module">
      <el-button type="danger" @click="deletePerson">确认</el-button>
    </div>
  </el-dialog>
</template>

<style scoped lang="scss">
  .module{
     margin-top: 20px;
   }
</style>